const { dataList } = require("../../../utils/yatijuan_1");
var localData = require("../../../utils/yatijuan_1");
const { dataList2 } = require("../../../utils/yatijuan_1answer");
var localData2 = require("../../../utils/yatijuan_1answer");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    time_second:0,
    time_minute:20,
    img:["/images/test/menu2.png","/images/test/menu1.png"],
    img_num:0,
    index:0,
    check:false,
    user_answer:[],
  },

  send:function(){
    let zhengque = 0;
    let cuowu = 0;
    if(this.data.user_answer.length==this.data.dataList.length){
      for(let i=0;i<this.data.user_answer.length;i++){
        if(this.data.user_answer[i]==this.data.dataList2[i].answer){
          zhengque = zhengque + 1;
        }else{
          cuowu = cuowu + 1;
        }
      }   
      wx.redirectTo({
        url: "/pages/test_baby/test3/test3?zhengque="+zhengque+"&cuowu="+cuowu
      })
    }else{
      wx.showToast({
        title: '您还有未答完的题，请仔细检查！',
        icon:"none"
      })
    }
  },

  answer:function(e){
    var that = this;
    let keika = e.currentTarget.id;
    let index = that.data.index;
    let user_answer = that.data.user_answer;
    if(keika != null){
      user_answer[index] = keika;
    }
  },

  btn1:function(){
    if(this.data.index==0){
      wx.showToast({
        title: '已经是第一页了！',
        icon:"none"
      })
    }else{
      this.setData({
        index:this.data.index - 1,
      });
    }
  },

  btn2:function(){
    if(this.data.index==dataList.length-1){
      wx.showToast({
        title: '已经是最后一道题了！',
        icon:"none"
      })
    }
    else{
      if(this.data.user_answer.length == this.data.index){
        wx.showToast({
          title: '答题选项不能为空',
          icon: 'none',
          duration: 2000
        })
      }else{
        this.setData({
          check:false,
          panduan:0,
          index:this.data.index + 1
        })
      }
    }
  },

  menu:function(){
    if(this.data.img_num==0){
      this.setData({
        img_num:1
      });
    }else{
      this.setData({
        img_num:0
      });
    }
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;

    that.setData({
      dataList:localData.dataList,
      dataList2:localData2.dataList2
    });

    let timer = setInterval(() => {
      if(this.data.time_second==0){
        this.data.time_second=60,
        this.setData({
          time_minute:this.data.time_minute-1
        })
      }
      this.setData({
        time_second:this.data.time_second-1
      })
      if(this.data.time_minute==0&&this.data.time_second==0){
        clearInterval(timer);
        wx.redirectTo({
          url: '/pages/test_baby/test3/test3',
        })
      }
    }, 1000);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})